var util = require('../../utils/util.js');
var utilMd5 = require('../../utils/md5.js');
var app = getApp();
var hasMore = true;
var goinMore = true;
var page = 1;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mingxiData: [],
    token: '',
    uid: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    
    app.LoginUserInfo(function (res) {
      if (res && res != -1) {
        that.setData({
          uid: res.uid,
          token: res.token,
        });
        this.loadMingxi(1);
      }
    });
    
  },

  loadMore: function(){
    if (hasMore && goinMore) {
      goinMore = false;
      page++;
      this.loadWz(page);
    } else {
      console.log("没有更多了");
    }
  },

  loadMingxi: function (cpage) {
    var that = this;
    util.api({
      method: "POST",
      data: {
        ac: "changelist",
        uid: that.data.uid,
        page: cpage,
        num: 20,
        "privatekey": utilMd5.hexMD5(that.data.uid + 'changelist' + that.data.token)
      },
      success: function (responseData) {
        var result = responseData.data;
        console.log("mingxi result " , result);
        if (result && result.length > 0) {
          for(var i = 0; i < result.length; i++){
            var date = new Date(result[i].ctime * 1000);
            result[i].formatTime = util.formatTime(date, '-', ':');
            var coinnum = result[i].coinnum;
            result[i].formatCoinnum = (coinnum/100.0).toFixed(2);
          }
          that.setData({
              mingxiData: that.data.mingxiData.concat(result),
          });
        } else {
          hasMore = false;
        }
        goinMore = true;
      }
    });
  },
})